﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Reflection;
using System.Windows.Forms;

namespace RI
{
    /// <summary>
    /// 系统设置
    /// </summary>
    public class SystemConfig : IDisposable
    {
        [DllImport("user32.dll")]
        private static extern IntPtr LoadCursorFromFile(string fileName);
        [DllImport("user32.dll")]
        private static extern IntPtr SetCursor(IntPtr cursorHandle);
        [DllImport("user32.dll")]
        private static extern uint DestroyCursor(IntPtr cursorHandle);
        /// <summary>
        /// 设置指定光标
        /// </summary>
        /// <param name="cursorFileName">光标文件名</param>
        /// <returns>光标对象</returns>
        public Cursor SetCurrentCursor(string cursorFileName, Cursor cur)
        {
            try
            {
                Cursor myCursor = new Cursor(cur.Handle);
                IntPtr colorCursorHandle = LoadCursorFromFile(cursorFileName);
                myCursor.GetType().InvokeMember("handle", BindingFlags.Public |
                BindingFlags.NonPublic | BindingFlags.Instance |
                BindingFlags.SetField, null, myCursor,
                new object[] { colorCursorHandle });
                return myCursor;
            }
            catch
            {
                return null;
            }
        }

        public void Dispose()
        {
        }
    }
}
